package com.qf.wangqing.sportsnews.utils;

import android.content.Context;
import android.support.v4.widget.SlidingPaneLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by WangQing on 2016/12/18.
 */

public class PagerEnableSlidingPaneLayout extends SlidingPaneLayout {
    private float mInitialMotionX;
    private float mInitialMotionY;
    private float mEdgeSlop;

    public PagerEnableSlidingPaneLayout(Context context) {
        super(context);
    }

    public PagerEnableSlidingPaneLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PagerEnableSlidingPaneLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
//        ViewConfiguration config=ViewConfiguration.get(context);
//        mEdgeSlop = config.getScaledEdgeSlop();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
//        switch (MotionEventCompat.getActionMasked(ev)) {
//            case MotionEvent.ACTION_DOWN:
//                mInitialMotionX = ev.getX();
//                mInitialMotionY = ev.getY();
//                break;
//
//
//            case MotionEvent.ACTION_MOVE:
//                final float x = ev.getX();
//                final float y = ev.getY();
//                // The user should always be able to "close" the pane, so we only check
//                // for child scrollability if the pane is currently closed.
//                if (mInitialMotionX > mEdgeSlop && !isOpen() && canScroll(this, false,
//                        Math.round(x - mInitialMotionX), Math.round(x), Math.round(y))) {
//
//                    // How do we set super.mIsUnableToDrag = true?
//
//                    // send the parent a cancel event
//                    MotionEvent cancelEvent = MotionEvent.obtain(ev);
//                    cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
//                    return super.onInterceptTouchEvent(cancelEvent);
//                }
//
//        }
//
//        return true;
        if (this.isOpen()) {
            return super.onInterceptTouchEvent(ev);
        }else {
            MotionEvent cancel = MotionEvent.obtain(ev);
            cancel.setAction(MotionEvent.ACTION_CANCEL);
            return super.onInterceptTouchEvent(cancel);
        }
    }
}
